package test;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Vector;

import javax.imageio.ImageIO;

//子弹类
public class Bullet {
	
	int x,y,h,w;
	BufferedImage[] imgs=new BufferedImage[2];
	int index=0;
	int cate=1;   //子弹种类 1 2双弹
	public Bullet(Plane p){
		if(p.bulletCate == 2) {
			cate = 2;
			index = 1;
		}
		h=14;
		w=6;
		x=p.x+p.w/2-w/2;//获取飞机的x坐标
		y=p.y;//获取飞机y坐标
		try {
			imgs[0]=ImageIO.read(getClass().getResource("/bullet.png"));
			imgs[1]=ImageIO.read(getClass().getResource("/bullet1.png"));

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	//绘制子弹
	public void paint(Graphics g){
		if(cate == 2){
			g.drawImage(imgs[index],x+9, y, null);
			g.drawImage(imgs[index],x-9, y, null);
		}
		else {
			g.drawImage(imgs[index],x, y, null);
		}
		
	}
	
	//子弹的移动
	public void move(Vector<Bullet> bullets){
		y-=14;
		
		if(y<=0-h){//判断当前对象是否越界  如果越界删除该对象
			bullets.remove(this);//this指代当前对象
		}
	}
	
}
